const { ipcMain } = require('electron');
const db = require('./index');

function setupDatabaseHandlers() {
  ipcMain.handle('db:query', async (event, { sql, params }) => {
    try {
      return { success: true, data: await db.query(sql, params) };
    } catch (error) {
      return { success: false, error: error.message };
    }
  });

  ipcMain.handle('db:execute', async (event, { sql, params }) => {
    try {
      return { success: true, data: await db.run(sql, params) };
    } catch (error) {
      return { success: false, error: error.message };
    }
  });

  ipcMain.handle('db:path', () => {
    return db.dbPath;
  });
}

module.exports = { setupDatabaseHandlers };